<?php

namespace App\Models;

class Config extends BaseModel
{

    public $timestamps = true;
    static $unguarded = true;
    public $table = 'config';

    // 文章类型
    const CONFIG_DATA_TYPE_STRING = 'string';
    const CONFIG_DATA_TYPE_TEXT = 'text';
    const CONFIG_DATA_TYPE_INT = 'int';
    const CONFIG_DATA_TYPE_BOOL = 'bool';
    const CONFIG_DATA_TYPE_ARRAY = 'array';
    const CONFIG_DATA_TYPE_DATETIME = 'datetime';
    const CONFIG_DATA_TYPE_DATA = 'date';
    const CONFIG_DATA_TYPE_FILE = 'file';

    // 状态
    public static function getDataType($status = null)
    {
        $listArr = [
            self::CONFIG_DATA_TYPE_STRING => 'string',
            self::CONFIG_DATA_TYPE_TEXT => 'text',
            self::CONFIG_DATA_TYPE_INT => 'int',
            self::CONFIG_DATA_TYPE_BOOL => 'bool',
            self::CONFIG_DATA_TYPE_ARRAY => 'array',
            self::CONFIG_DATA_TYPE_DATETIME => 'datetime',
            self::CONFIG_DATA_TYPE_DATA => 'date',
            self::CONFIG_DATA_TYPE_FILE => 'file',
        ];

        if (!is_null($status)) {
            return $listArr[$status] ?? '';
        }

        return $listArr;
    }

    public static function getValue($key = '')
    {
        if (!$key) return '';
        return Config::where("key", "=", $key)->value("value");
    }
}
